﻿using IPC.ListConnect.ListProprety;
using IPC.ListConnect.Profinet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace IPC.WinForm.BaseForm
{
    public partial class FrmNewChannel : Form
    {
        public string ChannelName { get; set; }
        public string ChannelType { get; set; }
        public string ChannelGuid { get; set; }

        public FrmNewChannel()
        {
            InitializeComponent();
            foreach (var item in typeof(ChannelType).GetEnumNames())
            {
                this.cbChannelType.Items.Add(item);
            }
            this.cbChannelType.SelectedIndex = -1;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ChannelName = this.txtChannelName.Text;
            ChannelType = this.cbChannelType.Text;
            string guid = Guid.NewGuid().ToString("N");
            ChannelGuid = guid;
            if (String.IsNullOrWhiteSpace(ChannelName))
            {
                MessageBox.Show("请填写通道名称");
                return;
            }
            if (String.IsNullOrWhiteSpace(ChannelType))
            {
                MessageBox.Show("请选择通道类型");
                return;
            }

            foreach (var item in EquipChannels.Instance.EquipChannelList)
            {
                if(item.ChannelName == ChannelName)
                {
                    MessageBox.Show("通道名称已存在！");
                    return;
                }
            }
            EquipChannel equipChannel = new EquipChannel()
            {
                Guid = guid,
                ChannelName = this.ChannelName,
                ChannelType = this.ChannelType
            };
            EquipChannels.Instance.EquipChannelList.Add(equipChannel);
            this.DialogResult = DialogResult.OK;
        }
    }
}
